<?php

namespace Home\Model;

class PushModel extends CommonModel
{
    public function send($channel, $alias, $title, $body, $data)
    {
        
                return '';
        // try {
        //     // 利用redis和rabbitmq实现解耦
        //     $redis = new \Redis();
        //     $redis->connect('127.0.0.1',6379);
        //     if(getenv('REDIS_PASS')){
        //         $redis->auth(getenv('REDIS_PASS'));
        //     }
        //     $redis->select(10);
        //     $time = time();
        //     $params = [
        //         'alias'=>$alias,
        //         'channel'=>$channel,
        //         'title'=>$title,
        //         'body'=>$body,
        //         'data'=>$data,
        //     ];
        //     $str_param = json_encode($params, JSON_UNESCAPED_UNICODE);
        //     $str_param = str_replace(':', "@#%#@&@##@!@#@&@@", $str_param);
        //     $redis->set(getenv('APP_NAME_EN').':alipush:' . $str_param, $time, 1);
        //     return;
        // } catch (\Exception $e) {
            
        // }

        $url = fullPath('/api/push/send');

        $curl = curl_init();

        curl_setopt_array($curl, [
            CURLOPT_URL => $url,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_SSL_VERIFYHOST => false,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => "POST",
            CURLOPT_POSTFIELDS => "alias=$alias&channel=$channel&title=$title&body=$body&data=$data",
            CURLOPT_HTTPHEADER => [
                "Content-Type:application/x-www-form-urlencoded"
            ],
        ]);

        $response = curl_exec($curl);

        $err = curl_error($curl);

        curl_close($curl);

        if ($err) {
            return "cURL Error #:" . $err;
        } else {
            return $response;
        }
    }
}
